using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using MydisDatas;
using UnityEditor;

public class TypeSpecif : MonoBehaviour
{
    public GameObject HerbDiseaseBook;//用来销毁病例书
    
    public GameObject _HerbLinePrefet;//草药行预制体
    public GameObject _DiseasePrefab; //病例行实例化]
    
    public List<GameObject> _HerbList; //草药本列表
    public List<GameObject> _DiseaseList; //草药本列表

    private Transform _Herbfatherobj;//草药父物体
    private Transform _Diseasefatherobj;//病例父物体
    
    public static TypeSpecif instance;
    
    // Start is called before the first frame update
     void Awake()
    {
        //寻找孙物体
        _Herbfatherobj = transform.Find("HerbPanel/HerbScrollRect/HerbGrid");
        _Diseasefatherobj = transform.Find("DiseasePanel/DiseaseGrid");

        instance = this;
        //创建病例行
        HerbalList MyHBlist = Resources.Load<HerbalList>("Datas/CarDB/medicincCarList");
        
        CreateHerbSprite(MyHBlist.MedicincCarLists[(int)HerbEnum.Fuling].HerbalImage,MyHBlist.MedicincCarLists[(int)HerbEnum.Fuling].HerbalDescription);
       // CreateHerbSprite(MyHBlist.MedicincCarLists[(int)HerbEnum.AJiao].HerbalImage,MyHBlist.MedicincCarLists[(int)HerbEnum.AJiao].HerbalDescription);
        CreateHerbSprite(MyHBlist.MedicincCarLists[(int)HerbEnum.ChaiHu].HerbalImage,MyHBlist.MedicincCarLists[(int)HerbEnum.ChaiHu].HerbalDescription);
        CreateHerbSprite(MyHBlist.MedicincCarLists[(int)HerbEnum.JieGeng].HerbalImage,MyHBlist.MedicincCarLists[(int)HerbEnum.JieGeng].HerbalDescription);

        CreateDiseaseSprite(MyHBlist.MedicincCarLists[(int)HerbEnum.AJiao].HerbalImage,DisaData.MyDisaDatas[(int)DiseasEnum.SangHang].Specif);
        CreateDiseaseSprite(MyHBlist.MedicincCarLists[(int)HerbEnum.AJiao].HerbalImage, DisaData.MyDisaDatas[(int)DiseasEnum.BingDuXing].Specif);
        CreateDiseaseSprite(MyHBlist.MedicincCarLists[(int)HerbEnum.AJiao].HerbalImage, DisaData.MyDisaDatas[(int)DiseasEnum.FeiReHouTeng].Specif);

    }
     
    
    //销毁病书
   public void HerbDiseaseDistory()
   {
       Destroy(HerbDiseaseBook.gameObject);
   }
   
    //创建草药
   public GameObject CreateHerbSprite(Sprite imageName,string DialogText)
   {
       GameObject HerbPrefect = _HerbLinePrefet;
       HerbPrefect.name = imageName.ToString();
       Transform _childText =  HerbPrefect.transform.Find("Text");
       Transform _childImage = HerbPrefect.transform.Find("Image");
       _childText.GetComponent<Text>().text = DialogText;
       _childImage.GetComponent<Image>().sprite =  imageName ;
       Instantiate(HerbPrefect,transform).transform.SetParent(_Herbfatherobj.transform);
       _HerbList.Add(HerbPrefect);
       return HerbPrefect;
   }
   
   //创建病例
   public GameObject CreateDiseaseSprite(Sprite imageName,string DialogText)
   {
       GameObject DiseasePrefect = _DiseasePrefab;
       DiseasePrefect.name = imageName.ToString();
       Transform _childText =  DiseasePrefect.transform.Find("Text");
       Transform _childImage = DiseasePrefect.transform.Find("Image");
       _childText.GetComponent<Text>().text = DialogText;
       _childImage.GetComponent<Image>().sprite =  imageName ;
       Instantiate(DiseasePrefect,transform).transform.SetParent(_Diseasefatherobj.transform);
       _DiseaseList.Add(DiseasePrefect);
       return DiseasePrefect;
   }


}
